package Lab12;

import java.io.*;
import java.util.ArrayList;

public class Ex12_7 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ArrayList<Loan> loanArrayList = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            loanArrayList.add(new Loan(i,i,i));
        }
        String fileName = "src/Lab12/Exercise12_7.dat";
//        https://blog.csdn.net/cc1969281777/article/details/87068106
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(fileName));
        outputStream.writeObject(loanArrayList);

        ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(fileName));
        Object object = inputStream.readObject();
        ArrayList<Loan> loanArrayListRead = (ArrayList<Loan>) object;
        for (Loan loan : loanArrayListRead) {
            System.out.println(loan.getMonthlyPayment());
        }
    }
}
